package com.cj.library.widget.dialog;

import android.app.Activity;
import android.support.annotation.ColorInt;
import android.support.annotation.IdRes;
import android.view.View;

import com.cj.library.widget.R;
import com.cj.library.widget.recyclerview.adapter.BaseViewHolder;
import com.cj.library.widget.utiles.DensityUtils;

/**
 * Created by peter on 2016/9/18.
 */
public abstract class CJBaseDialog {

    protected CJDialog dialog;
    protected BaseViewHolder viewHolder;

    public CJBaseDialog(Activity mAty) {
        dialog = new CJDialog.Builder(mAty)
                .setContentView(getContentViewID())
                .setWight((int) (DensityUtils.getScreenW(mAty) * 0.8f))
                .create();
        viewHolder = dialog.getViewHolder();
    }

    /**
     * 返回布局ID
     *
     * @return @{@link android.support.annotation.LayoutRes}
     */
    protected abstract int getContentViewID();

    public void show() {
        dialog.show();
    }

    public void close() {
        dialog.dismiss();
    }

    public CJBaseDialog setTitle(CharSequence title) {
        viewHolder.setText(R.id.dialog_title, title);
        return this;
    }

    public CJBaseDialog setTitleColor(@ColorInt int color) {
        viewHolder.setTextColor(R.id.dialog_title, color);
        return this;
    }

    public CJBaseDialog setTitleSize(float size) {
        viewHolder.setTextSize(R.id.dialog_title, size);
        return this;
    }

    public CJBaseDialog setLeftBtnOnClickListener(View.OnClickListener l) {
        viewHolder.setOnClickListener(R.id.dialog_sure, l);
        return this;
    }

    public CJBaseDialog setRightBtnOnClickListener(View.OnClickListener l) {
        viewHolder.setOnClickListener(R.id.dialog_cancel, l);
        return this;
    }

    public CJBaseDialog setOnViewClickListener(@IdRes int viewId, View.OnClickListener l) {
        viewHolder.setOnClickListener(viewId, l);
        return this;
    }
}
